﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace WinServicesSample
{
    partial class WinServicesDemo : ServiceBase
    {
        public WinServicesDemo()
        {
            InitializeComponent();
           
        }

        protected override void OnStart(string[] args)
        {
            // TODO: Add code here to start your service.
            System.Timers.Timer myTimer = new System.Timers.Timer();
            myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
            myTimer.Interval = 2000;
            myTimer.Enabled = true;
            LogHandler.WriteLog("service start:" + DateTime.Now.ToLongTimeString());
        }

        protected override void OnStop()
        {
            // TODO: Add code here to perform any tear-down necessary to stop your service.
            LogHandler.WriteLog("service end:" + DateTime.Now.ToLongTimeString());
        }

        void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(ServiceBLL.RunServiceBLL));
            thread.Start();
        }

    }
}
